/** 
 * File-Name:ArticleDao.java
 *
 * Created on 2011-6-2 下午03:45:50
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package site.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

import neoutil.CommonDao;
import site.entity.Article;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-6-2 下午03:45:50
 */
public class ArticleDao extends CommonDao<Article, Long> {
	private String SQL_INSERT = "INSERT INTO article(uuid, title, content, imagePath, filePath, authorId, cid, categoryId, organizationId, publishDate, updateDate, status, entityStatus, reserve01, reserve02, reserve03, reserve04, reserve05) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	private String SQL_UPDATE = "UPDATE article SET uuid=?, title=?, content=?, imagePath=?, filePath=?, authorId=?, cid=?, categoryId=?, organizationId=?, updateDate=?, status=?, entityStatus=?, reserve01=?, reserve02=?, reserve03=?, reserve04=?, reserve05=? WHERE id=?";

	public ArticleDao(Connection connection) {
		super(Article.class, connection);
	}

	public void save(Article article) throws SQLException {
		Object[] params = { article.getUuid(), article.getTitle(),
				article.getContent(), article.getImagePath(),
				article.getFilePath(), article.getAuthorId(), article.getCid(),
				article.getCategoryId(), article.getOrganizationId(),
				new Date(), new Date(), article.getStatus(),
				article.getEntityStatus(), article.getReserve01(),
				article.getReserve02(), article.getReserve03(),
				article.getReserve04(), article.getReserve05() };
		execute(SQL_INSERT, params);
	}

	public void update(Article article) throws SQLException {
		Object[] params = { article.getUuid(), article.getTitle(),
				article.getContent(), article.getImagePath(),
				article.getFilePath(), article.getAuthorId(), article.getCid(),
				article.getCategoryId(), article.getOrganizationId(),
				new Date(), article.getStatus(), article.getEntityStatus(),
				article.getReserve01(), article.getReserve02(),
				article.getReserve03(), article.getReserve04(),
				article.getReserve05(), article.getId() };
		execute(SQL_UPDATE, params);
	}
}
